R Markdown Individual Project

Due: December 12, 2023

Individual project should be submitted as an R Markdown file with links to Google colab notes where necessary. Homework should be turned in on Sakai.

Introduction

Residential loan applications processed by banks in Chicago play a vital role in the ever-evolving local real estate landscape. However, amidst a global economic crisis, it is pertinent to analyze temporal trends in loan application volumes, seeking patterns and fluctuations over distinct time periods. Our examination extends to the distribution of loan applications across genders and ethnicities, where descriptive statistics are employed to identify potential significant differences, hinting at potential inequities. Exploring the range and distribution of loan amounts, our objective is to grasp the typical size of residential loans. Furthermore, we delve into the factors influencing interest rates on approved loans, identifying significant variables. Lastly, we scrutinize how loan amounts vary across the five main loan purposes, offering nuanced insights into the diverse financial needs associated with different loan intents.

Dataset

The dataset provides a comprehensive perspective on residential loan applications processed by participating banks operating within the city limits of Chicago, emphasizing transparency in public information to uphold lending equity standards. https://data.cityofchicago.org/Administration-Finance/Lending-Equity-Residential-Lending/b77m-uuhb/about_data Spanning the years 2021 to 2023, the dataset encompasses 46 columns, each representing distinct variables such as Reporting year, bank, loan amount, loan purpose, loan type, interest rate, ethnicity of the applicant, gender of the applicant, and property value. Comprising a robust 78.1k rows, each row corresponds to a unique loan application, offering profound insights into the myriad factors shaping the real estate landscape. This valuable information is curated from the Chicago Data Portal, sourced from the Department of Finance of the city of Chicago, ensuring reliability and relevance.

Methods

Variations of the volume of residential loan applications over time in Chicago.

Temporal trends, patterns, and fluctuations over different periods. To start with the analysis the data was cleaned by removing missing values in the Application date column, and then this cleared variable was used with “ggplot2” to create a basic time series histogram, allowing an easy visualization of the number of applications over time. To enhance user engagement the data is then converted into an interactive form by using the “plotly” package, which shows fluctuations and patterns in the volume of residential loan applications.

Distribution of loan applications among different genders and ethnicities.

To visualize the gender distribution among the loan applications, a bar chart was created by using “ggplot2”, then to make an interactive plot, the “plotly” package was applied. A similar method was followed to visualize ethnicity and race distribution, and a posterior analysis was performed to understand the dynamics of the patterns.

Range and distribution of loan amounts for residential lending in Chicago.

The column Loann Amount was first cleared and converted to a numeric format, then, with the use of the “ggplot2” package a dispersion scatter plot was generated, where the x-axis represents the Loan Amount and the y-axis the loan purpose, each point is colored by the taken action. Additionally, the plot was converted to an interactive graphic to show detailed information about the loan purpose distribution.

Factors (Variables) that influence the interest rates assigned to approved loans.

To determine which factors, influence the most, a logistic regression model was constructed and the variables analyzed corresponded to Open End Line of Credit, Loan Purpose, Bank Reason for Denial, Race, Ethnicity, and Gender of Applicant or Borrower, and the correspondent variables of the co-applicants. Then the summary function was used to print the details of the model, including coefficients, standard errors, z-values, and p-values that assess the significance of each predictor.

Distribution of loan amount vary across the 5 main loan purposes.

To analyze how loan amounts differ across the five main loan purposes and assess potential variations in mean loan amounts among these purposes, the first step involved converting the “Loan Amount” variable to a numeric. Following this, an interactive box plot graph was generated using the Plotly and ggplot2 libraries. This graphical representation serves to illustrate the distribution of loan amounts for each loan purpose. On the graph, the x-axis corresponds to the loan purpose categories, the y-axis reflects the loan amounts, and each box plot is color-coded based on the specific loan purpose. This interactive plot offers a dynamic and insightful visualization of the diversity in loan amounts associated with each distinct loan purpose.

The rest is in the report in PDF

Appendix of code in R and Python

if (!require(dplyr)) {
  install.packages("dplyr")
  library(dplyr)
}
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
if (!require(ggplot2)) {
  install.packages("ggplot2")
  library(ggplot2)
}
## Loading required package: ggplot2
if (!require(plotly)) {
  install.packages("plotly")
  library(plotly)
}
## Loading required package: plotly
## Warning: package 'plotly' was built under R version 4.3.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
if (!require(tidyverse)) {
  install.packages("tidyverse")
  library(tidyverse)
}
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ✔ readr     2.1.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ plotly::filter() masks dplyr::filter(), stats::filter()
## ✖ dplyr::lag()     masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
if (!require(caret)) {
  install.packages("caret")
  library(caret)
}
## Loading required package: caret
## Warning: package 'caret' was built under R version 4.3.2
## Loading required package: lattice
## 
## Attaching package: 'caret'
## 
## The following object is masked from 'package:purrr':
## 
##     lift
if (!require(shiny)) {
  install.packages("shiny")
  library(shiny)
}
## Loading required package: shiny
## Warning: package 'shiny' was built under R version 4.3.2
if (!require(lubridate)) {
  install.packages("lubridate")
  library(lubridate)
}

if (!require(forecast)) {
  install.packages("forecast")
  library(forecast)
}
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 4.3.2
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
loans_DF <- read.csv("https://raw.githubusercontent.com/LexoBrunett/STAT408_LexoBrunett/main/Datasets/Lending_Equity_-_Residential_Lending_Treated.csv", sep = ";")

# Supongamos que loans_DF$Application.Date es un factor con el formato MM/DD/YYYY
loans_DF$Application.Date <- as.Date(loans_DF$Application.Date, format = "%m/%d/%Y")

# Filtrar solo las filas con fechas válidas
loans_DF <- loans_DF[!is.na(loans_DF$Application.Date),]

# Filtrar fechas desde 2020 hasta 2022
loans_DF <- subset(loans_DF, year(Application.Date) >= 2020 & year(Application.Date) <= 2022)

head(loans_DF)
##   Reporting.Year            Bank RFP.Source  Data.Description Census.Tract
## 1           2022 Associated Bank   Form A-1 Residential Loans  17031020701
## 2           2022 Associated Bank   Form A-1 Residential Loans  17031242000
## 3           2023 Associated Bank   Form A-1 Residential Loans  17031580501
## 4           2022 Associated Bank   Form A-1 Residential Loans  17031210502
## 5           2022 Associated Bank   Form A-1 Residential Loans  17031110100
## 6           2022 Associated Bank   Form A-1 Residential Loans  17031062600
##           Action.Taken Total.Units   Open.End.Line.of.Credit
## 1    1-Loan originated           1 1-Open-end line of credit
## 2    1-Loan originated           1 1-Open-end line of credit
## 3 3-Application denied           1 1-Open-end line of credit
## 4    1-Loan originated           3 1-Open-end line of credit
## 5    1-Loan originated           1 1-Open-end line of credit
## 6 3-Application denied           1 1-Open-end line of credit
##                                                            Loan.Type
## 1 1-Conventional (not insured or guaranteed by FHA, VA, RHS, or FSA)
## 2 1-Conventional (not insured or guaranteed by FHA, VA, RHS, or FSA)
## 3 1-Conventional (not insured or guaranteed by FHA, VA, RHS, or FSA)
## 4 1-Conventional (not insured or guaranteed by FHA, VA, RHS, or FSA)
## 5 1-Conventional (not insured or guaranteed by FHA, VA, RHS, or FSA)
## 6 1-Conventional (not insured or guaranteed by FHA, VA, RHS, or FSA)
##         Loan.Purpose Loan.Amount Application.Date Interest.Rate
## 1 2-Home Improvement       40000       2021-07-09           425
## 2       31-Refinance      120000       2021-07-15          3625
## 3 2-Home Improvement       20000       2022-03-15            NA
## 4 2-Home Improvement      150000       2021-07-16          3375
## 5       31-Refinance      100000       2021-08-05          3125
## 6       31-Refinance      208000       2021-08-27            NA
##   Loan.Term..Months. Total.Points.and.Fees                     Lien.Status
## 1                360                    NA 2-Secured by a subordinate lien
## 2                360                    NA 2-Secured by a subordinate lien
## 3                360                    NA 2-Secured by a subordinate lien
## 4                360                    NA 2-Secured by a subordinate lien
## 5                360                    NA       1-Secured by a first lien
## 6                360                    NA 2-Secured by a subordinate lien
##   Property.Value Combined.Loan.value.Ratio Purchase.Price Down.Payment.Amount
## 1         660000                      8979             NA                  NA
## 2         770000                      8742             NA                  NA
## 3         353000                      5933             NA                  NA
## 4         540000                      7434         240000                  NA
## 5         401000                      2494             NA                  NA
## 6         950000                      8055             NA                  NA
##    Reason.for.Denial..1. Race.of.Applicant.or.Borrower..1.
## 1      10-Not applicable                           5-White
## 2      10-Not applicable       3-Black or African American
## 3 1-Debt-to-income ratio                           5-White
## 4      10-Not applicable                           5-White
## 5      10-Not applicable                           5-White
## 6 1-Debt-to-income ratio                           5-White
##   Race.of.Co.Applicant.or.Borrower..1. Ethnicity.of.Applicant.or.Borrower..1.
## 1                              5-White               2-Not Hispanic or Latino
## 2                    8-No co-applicant               2-Not Hispanic or Latino
## 3                    8-No co-applicant                   1-Hispanic or Latino
## 4                    8-No co-applicant               2-Not Hispanic or Latino
## 5                    8-No co-applicant               2-Not Hispanic or Latino
## 6                    8-No co-applicant               2-Not Hispanic or Latino
##   Ethnicity.of.Co.Applicant.or.Borrower..1. Sex.of.Applicant.or.Borrower
## 1                  2-Not Hispanic or Latino                       1-Male
## 2                                   5-White                       1-Male
## 3                                   5-White                       1-Male
## 4                                   5-White                       1-Male
## 5                                   5-White                     2-Female
## 6                                   5-White                       1-Male
##   Sex.of.Co.Applicant.or.Borrower
## 1                        2-Female
## 2               5-No co-applicant
## 3               5-No co-applicant
## 4               5-No co-applicant
## 5               5-No co-applicant
## 6               5-No co-applicant
#str(loans_DF)

# Contar la cantidad de valores NA en cada columna
#na_counts <- colSums(is.na(loans_DF))

# Mostrar los resultados
#print(na_counts)


# Contar la cantidad de valores vacíos en cada columna
#empty_counts <- colSums(loans_DF == "-")

# Mostrar los resultados
#print(empty_counts)

# Mostrar solo las columnas con valores vacíos
#columns_with_empty <- names(empty_counts[empty_counts > 0])
#print(columns_with_empty)

#attach(loans_DF);

# Asegúrate de que los nombres en columns_char coincidan exactamente
columns_char <- c("RFP.Source", "Data.Description", "Open.End.Line.of.Credit", "Action.Taken", "Loan.Purpose", "Race.of.Applicant.or.Borrower..1.", "Ethnicity.of.Applicant.or.Borrower..1.", "Sex.of.Applicant.or.Borrower", "Bank", "Loan.Type", "Reason.for.Denial..1.", "Race.of.Co.Applicant.or.Borrower..1.", "Ethnicity.of.Co.Applicant.or.Borrower..1.", "Sex.of.Co.Applicant.or.Borrower")

# Convertir las columnas seleccionadas a factores
for (col in columns_char) {
  loans_DF[[col]] <- factor(loans_DF[[col]])
}

bklabka

#str(loans_DF)

# Obtener las columnas que contienen caracteres
columns_with_chars <- sapply(loans_DF, function(x) is.factor(x))

# Iterar sobre las columnas con caracteres
for (column in names(loans_DF)[columns_with_chars]) {
  
  # Crear un gráfico de barras (histograma de frecuencias)
  histogram_plot <- ggplot(loans_DF, aes(x = !!as.name(column))) +
    geom_bar(fill = "blue") +
    labs(title = paste("Histograma de Frecuencias para", column),
         x = column,
         y = "Frecuencia") +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))  # Ajusta el ángulo según tu preferencia
  
  # Mostrar el gráfico
  print(histogram_plot)
}

# Crear la tabla de contingencia
table_Contingency_Applicant <- ftable(loans_DF[, c("Race.of.Applicant.or.Borrower..1.","Action.Taken")])


table_Contingency_Coapplicant <- ftable(loans_DF[, c("Race.of.Co.Applicant.or.Borrower..1.", "Action.Taken")])


# Realizar el test de chi cuadrado
results_Chi_Test_Applicant <- chisq.test(table_Contingency_Applicant)
## Warning in chisq.test(table_Contingency_Applicant): Chi-squared approximation
## may be incorrect
# Mostrar el resultado
print(results_Chi_Test_Applicant)
## 
##  Pearson's Chi-squared test
## 
## data:  table_Contingency_Applicant
## X-squared = 1215.2, df = 16, p-value < 2.2e-16
# Realizar el test de chi cuadrado
results_Chi_Test_Coapplicant <- chisq.test(table_Contingency_Coapplicant)
## Warning in chisq.test(table_Contingency_Coapplicant): Chi-squared approximation
## may be incorrect
# Mostrar el resultado
print(results_Chi_Test_Coapplicant)
## 
##  Pearson's Chi-squared test
## 
## data:  table_Contingency_Coapplicant
## X-squared = 526.94, df = 15, p-value < 2.2e-16

1. Answer the questions below:

2. Answer the questions below:

Question 2: “How does the distribution of loan applications vary across different genders and ethnicities?” Use descriptive statistics to understand the distribution of loan applications to investigate whether there are significant differences among genders and ethnicities.

# Crea un gráfico de barras para la distribución por género y Action.Taken
gender_plot <- ggplot(loans_DF, aes(x = Sex.of.Applicant.or.Borrower, fill = Action.Taken)) +
  geom_bar(position = "dodge") +
  labs(title = "Distribution of Loan Applications by Gender and Action Taken",
       x = "Gender",
       y = "Number of Applications") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_manual(values = c("1-Loan originated" = "green", "3-Application denied" = "red"))

# Convierte el gráfico a un gráfico interactivo con plotly
gender_interactive_plot <- ggplotly(gender_plot)

# Muestra el gráfico interactivo
gender_interactive_plot
# Crea un gráfico de barras para la distribución por etnia y Action.Taken
ethnicity_plot <- ggplot(loans_DF, aes(x = Ethnicity.of.Applicant.or.Borrower..1., fill = Action.Taken)) +
  geom_bar(position = "dodge") +
  labs(title = "Distribution of Loan Applications by Ethnicity and Action Taken",
       x = "Ethnicity",
       y = "Number of Applications") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_manual(values = c("1-Loan originated" = "green", "3-Application denied" = "red"))

# Convierte el gráfico a un gráfico interactivo con plotly
ethnicity_interactive_plot <- ggplotly(ethnicity_plot)

# Muestra el gráfico interactivo
ethnicity_interactive_plot
# Crea un gráfico de barras para la distribución por raza y Action.Taken
race_plot <- ggplot(loans_DF, aes(x = Race.of.Applicant.or.Borrower..1., fill = Action.Taken)) +
  geom_bar(position = "dodge") +
  labs(title = "Distribution of Loan Applications by Race and Action Taken",
       x = "Race",
       y = "Number of Applications") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_manual(values = c("1-Loan originated" = "green", "3-Application denied" = "red"))

# Convierte el gráfico a un gráfico interactivo con plotly
race_interactive_plot <- ggplotly(race_plot)

# Muestra el gráfico interactivo
race_interactive_plot

3. Answer the questions below:

Question 3: “What is the distribution of loan amounts for residential lending in Chicago?” Explore the range and distribution of loan amounts to understand the typical size of residential loans.

# Convierte 'Loan Amount' a numérico si no está en ese formato
loans_DF$Loan.Amount <- as.numeric(as.character(loans_DF$Loan.Amount))

# Crea un scatter plot
scatter_plot <- ggplot(loans_DF, aes(x = Loan.Amount, y = Loan.Purpose, color = factor(Action.Taken))) +
  geom_point() +
  labs(title = "Scatter Plot of Loan Amount vs Loan Purpose",
       x = "Loan Amount",
       y = "Loan Purpose",
       color = "Taken Action") +
  scale_x_continuous(labels = scales::comma_format()) +  # Agrega comas al formato
  scale_color_manual(values = c("green", "red"))  # Paleta de colores para cada categoría

# Convierte el gráfico a un gráfico interactivo con plotly
scatter_interactive_plot <- ggplotly(scatter_plot)

# Muestra el gráfico interactivo
scatter_interactive_plot
# Convierte 'Loan Amount' a numérico si no está en ese formato
loans_DF$Loan.Amount <- as.numeric(as.character(loans_DF$Loan.Amount))

# Crea un gráfico interactivo de barras con plotly
interactive_plot <- ggplot(loans_DF, aes(x = Loan.Amount, fill = factor(Action.Taken))) +
  geom_bar(position = "stack", stat = "count", width = 1000) +
  labs(title = "Distribution of Loan Amounts by Taken Action",
       x = "Loan Amount",
       y = "Frequency",
       fill = "Taken Action") +
  scale_x_continuous(labels = scales::comma_format()) +  # Agrega comas al formato
  scale_fill_manual(values = c("green", "red"))  # Paleta de colores para cada categoría

# Convierte el gráfico a un gráfico interactivo con plotly
interactive_plot <- ggplotly(interactive_plot)
## Warning: `position_stack()` requires non-overlapping x intervals
# Muestra el gráfico interactivo
interactive_plot

Question 4: “Which factors influence the interest rates assigned to approved loans?” Identify the variables (e.g., loan amount, loan term, applicant’s characteristics) that significantly impact the interest rates assigned to approved loans.

# Ajusta el modelo lineal
model_race <- lm(Interest.Rate ~ Loan.Amount + Loan.Term..Months. + Loan.Purpose + Race.of.Applicant.or.Borrower..1., data = loans_DF)

# Resumen del modelo
summary(model_race)
## 
## Call:
## lm(formula = Interest.Rate ~ Loan.Amount + Loan.Term..Months. + 
##     Loan.Purpose + Race.of.Applicant.or.Borrower..1., data = loans_DF)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -2302  -1438   -779   1343   7023 
## 
## Coefficients:
##                                                                                                                        Estimate
## (Intercept)                                                                                                           1.533e+03
## Loan.Amount                                                                                                          -3.025e-05
## Loan.Term..Months.                                                                                                    1.793e+00
## Loan.Purpose2-Home Improvement                                                                                       -1.424e+03
## Loan.Purpose31-Refinance                                                                                             -4.857e+02
## Loan.Purpose32-Cash Out                                                                                              -2.707e+02
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                             -1.526e+02
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                     -2.037e+02
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                          -8.306e+01
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                         -3.470e+02
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                         -1.150e+02
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            1.343e+02
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                       -3.314e+02
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                      -3.943e+02
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                         -9.000e+00
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          3.837e+02
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             1.185e+03
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                           -2.917e+02
## Race.of.Applicant.or.Borrower..1.5-White                                                                             -1.417e+02
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application -1.068e+02
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                    -5.025e+02
##                                                                                                                      Std. Error
## (Intercept)                                                                                                           1.841e+02
## Loan.Amount                                                                                                           1.039e-05
## Loan.Term..Months.                                                                                                    1.677e-01
## Loan.Purpose2-Home Improvement                                                                                        5.537e+01
## Loan.Purpose31-Refinance                                                                                              2.934e+01
## Loan.Purpose32-Cash Out                                                                                               4.295e+01
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              1.807e+02
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      1.952e+02
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           2.496e+02
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          2.384e+02
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          7.069e+02
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            3.669e+02
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        3.481e+02
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       3.232e+02
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          1.786e+02
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          8.569e+02
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             1.687e+03
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            4.669e+02
## Race.of.Applicant.or.Borrower..1.5-White                                                                              1.747e+02
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  1.782e+02
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     2.307e+02
##                                                                                                                      t value
## (Intercept)                                                                                                            8.325
## Loan.Amount                                                                                                           -2.912
## Loan.Term..Months.                                                                                                    10.693
## Loan.Purpose2-Home Improvement                                                                                       -25.709
## Loan.Purpose31-Refinance                                                                                             -16.552
## Loan.Purpose32-Cash Out                                                                                               -6.303
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              -0.844
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      -1.043
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           -0.333
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          -1.455
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          -0.163
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                             0.366
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        -0.952
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       -1.220
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          -0.050
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                           0.448
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                              0.703
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            -0.625
## Race.of.Applicant.or.Borrower..1.5-White                                                                              -0.811
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  -0.600
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     -2.178
##                                                                                                                      Pr(>|t|)
## (Intercept)                                                                                                           < 2e-16
## Loan.Amount                                                                                                           0.00359
## Loan.Term..Months.                                                                                                    < 2e-16
## Loan.Purpose2-Home Improvement                                                                                        < 2e-16
## Loan.Purpose31-Refinance                                                                                              < 2e-16
## Loan.Purpose32-Cash Out                                                                                                 3e-10
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              0.39845
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      0.29681
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           0.73934
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          0.14562
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          0.87082
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            0.71426
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        0.34101
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       0.22243
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          0.95980
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          0.65434
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             0.48237
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            0.53219
## Race.of.Applicant.or.Borrower..1.5-White                                                                              0.41752
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  0.54879
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     0.02940
##                                                                                                                         
## (Intercept)                                                                                                          ***
## Loan.Amount                                                                                                          ** 
## Loan.Term..Months.                                                                                                   ***
## Loan.Purpose2-Home Improvement                                                                                       ***
## Loan.Purpose31-Refinance                                                                                             ***
## Loan.Purpose32-Cash Out                                                                                              ***
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                        
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                             
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                            
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                            
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                              
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                          
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                         
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                            
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                            
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                               
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                              
## Race.of.Applicant.or.Borrower..1.5-White                                                                                
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application    
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                    *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1678 on 18075 degrees of freedom
##   (4904 observations deleted due to missingness)
## Multiple R-squared:  0.05566,    Adjusted R-squared:  0.05461 
## F-statistic: 53.27 on 20 and 18075 DF,  p-value: < 2.2e-16

blablabla

# Ajusta el modelo lineal
model_ethici <- lm(Interest.Rate ~ Loan.Amount + Loan.Term..Months. + Loan.Purpose + Race.of.Applicant.or.Borrower..1., data = loans_DF)

# Resumen del modelo
summary(model_ethici)
## 
## Call:
## lm(formula = Interest.Rate ~ Loan.Amount + Loan.Term..Months. + 
##     Loan.Purpose + Race.of.Applicant.or.Borrower..1., data = loans_DF)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -2302  -1438   -779   1343   7023 
## 
## Coefficients:
##                                                                                                                        Estimate
## (Intercept)                                                                                                           1.533e+03
## Loan.Amount                                                                                                          -3.025e-05
## Loan.Term..Months.                                                                                                    1.793e+00
## Loan.Purpose2-Home Improvement                                                                                       -1.424e+03
## Loan.Purpose31-Refinance                                                                                             -4.857e+02
## Loan.Purpose32-Cash Out                                                                                              -2.707e+02
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                             -1.526e+02
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                     -2.037e+02
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                          -8.306e+01
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                         -3.470e+02
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                         -1.150e+02
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            1.343e+02
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                       -3.314e+02
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                      -3.943e+02
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                         -9.000e+00
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          3.837e+02
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             1.185e+03
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                           -2.917e+02
## Race.of.Applicant.or.Borrower..1.5-White                                                                             -1.417e+02
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application -1.068e+02
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                    -5.025e+02
##                                                                                                                      Std. Error
## (Intercept)                                                                                                           1.841e+02
## Loan.Amount                                                                                                           1.039e-05
## Loan.Term..Months.                                                                                                    1.677e-01
## Loan.Purpose2-Home Improvement                                                                                        5.537e+01
## Loan.Purpose31-Refinance                                                                                              2.934e+01
## Loan.Purpose32-Cash Out                                                                                               4.295e+01
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              1.807e+02
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      1.952e+02
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           2.496e+02
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          2.384e+02
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          7.069e+02
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            3.669e+02
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        3.481e+02
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       3.232e+02
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          1.786e+02
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          8.569e+02
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             1.687e+03
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            4.669e+02
## Race.of.Applicant.or.Borrower..1.5-White                                                                              1.747e+02
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  1.782e+02
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     2.307e+02
##                                                                                                                      t value
## (Intercept)                                                                                                            8.325
## Loan.Amount                                                                                                           -2.912
## Loan.Term..Months.                                                                                                    10.693
## Loan.Purpose2-Home Improvement                                                                                       -25.709
## Loan.Purpose31-Refinance                                                                                             -16.552
## Loan.Purpose32-Cash Out                                                                                               -6.303
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              -0.844
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      -1.043
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           -0.333
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          -1.455
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          -0.163
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                             0.366
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        -0.952
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       -1.220
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          -0.050
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                           0.448
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                              0.703
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            -0.625
## Race.of.Applicant.or.Borrower..1.5-White                                                                              -0.811
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  -0.600
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     -2.178
##                                                                                                                      Pr(>|t|)
## (Intercept)                                                                                                           < 2e-16
## Loan.Amount                                                                                                           0.00359
## Loan.Term..Months.                                                                                                    < 2e-16
## Loan.Purpose2-Home Improvement                                                                                        < 2e-16
## Loan.Purpose31-Refinance                                                                                              < 2e-16
## Loan.Purpose32-Cash Out                                                                                                 3e-10
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              0.39845
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      0.29681
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           0.73934
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          0.14562
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          0.87082
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            0.71426
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        0.34101
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       0.22243
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          0.95980
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          0.65434
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             0.48237
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            0.53219
## Race.of.Applicant.or.Borrower..1.5-White                                                                              0.41752
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  0.54879
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     0.02940
##                                                                                                                         
## (Intercept)                                                                                                          ***
## Loan.Amount                                                                                                          ** 
## Loan.Term..Months.                                                                                                   ***
## Loan.Purpose2-Home Improvement                                                                                       ***
## Loan.Purpose31-Refinance                                                                                             ***
## Loan.Purpose32-Cash Out                                                                                              ***
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                        
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                             
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                            
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                            
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                              
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                          
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                         
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                            
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                            
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                               
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                              
## Race.of.Applicant.or.Borrower..1.5-White                                                                                
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application    
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                    *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1678 on 18075 degrees of freedom
##   (4904 observations deleted due to missingness)
## Multiple R-squared:  0.05566,    Adjusted R-squared:  0.05461 
## F-statistic: 53.27 on 20 and 18075 DF,  p-value: < 2.2e-16

blabla

# Ajusta el modelo lineal
model_sex <- lm(Interest.Rate ~ Loan.Amount + Loan.Term..Months. + Loan.Purpose + Race.of.Applicant.or.Borrower..1., data = loans_DF)

# Resumen del modelo
summary(model_sex)
## 
## Call:
## lm(formula = Interest.Rate ~ Loan.Amount + Loan.Term..Months. + 
##     Loan.Purpose + Race.of.Applicant.or.Borrower..1., data = loans_DF)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -2302  -1438   -779   1343   7023 
## 
## Coefficients:
##                                                                                                                        Estimate
## (Intercept)                                                                                                           1.533e+03
## Loan.Amount                                                                                                          -3.025e-05
## Loan.Term..Months.                                                                                                    1.793e+00
## Loan.Purpose2-Home Improvement                                                                                       -1.424e+03
## Loan.Purpose31-Refinance                                                                                             -4.857e+02
## Loan.Purpose32-Cash Out                                                                                              -2.707e+02
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                             -1.526e+02
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                     -2.037e+02
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                          -8.306e+01
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                         -3.470e+02
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                         -1.150e+02
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            1.343e+02
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                       -3.314e+02
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                      -3.943e+02
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                         -9.000e+00
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          3.837e+02
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             1.185e+03
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                           -2.917e+02
## Race.of.Applicant.or.Borrower..1.5-White                                                                             -1.417e+02
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application -1.068e+02
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                    -5.025e+02
##                                                                                                                      Std. Error
## (Intercept)                                                                                                           1.841e+02
## Loan.Amount                                                                                                           1.039e-05
## Loan.Term..Months.                                                                                                    1.677e-01
## Loan.Purpose2-Home Improvement                                                                                        5.537e+01
## Loan.Purpose31-Refinance                                                                                              2.934e+01
## Loan.Purpose32-Cash Out                                                                                               4.295e+01
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              1.807e+02
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      1.952e+02
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           2.496e+02
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          2.384e+02
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          7.069e+02
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            3.669e+02
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        3.481e+02
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       3.232e+02
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          1.786e+02
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          8.569e+02
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             1.687e+03
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            4.669e+02
## Race.of.Applicant.or.Borrower..1.5-White                                                                              1.747e+02
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  1.782e+02
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     2.307e+02
##                                                                                                                      t value
## (Intercept)                                                                                                            8.325
## Loan.Amount                                                                                                           -2.912
## Loan.Term..Months.                                                                                                    10.693
## Loan.Purpose2-Home Improvement                                                                                       -25.709
## Loan.Purpose31-Refinance                                                                                             -16.552
## Loan.Purpose32-Cash Out                                                                                               -6.303
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              -0.844
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      -1.043
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           -0.333
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          -1.455
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          -0.163
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                             0.366
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        -0.952
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       -1.220
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          -0.050
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                           0.448
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                              0.703
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            -0.625
## Race.of.Applicant.or.Borrower..1.5-White                                                                              -0.811
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  -0.600
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     -2.178
##                                                                                                                      Pr(>|t|)
## (Intercept)                                                                                                           < 2e-16
## Loan.Amount                                                                                                           0.00359
## Loan.Term..Months.                                                                                                    < 2e-16
## Loan.Purpose2-Home Improvement                                                                                        < 2e-16
## Loan.Purpose31-Refinance                                                                                              < 2e-16
## Loan.Purpose32-Cash Out                                                                                                 3e-10
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                              0.39845
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                      0.29681
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                           0.73934
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                          0.14562
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                          0.87082
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                            0.71426
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                        0.34101
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                       0.22243
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                          0.95980
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                          0.65434
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                             0.48237
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                            0.53219
## Race.of.Applicant.or.Borrower..1.5-White                                                                              0.41752
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  0.54879
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                     0.02940
##                                                                                                                         
## (Intercept)                                                                                                          ***
## Loan.Amount                                                                                                          ** 
## Loan.Term..Months.                                                                                                   ***
## Loan.Purpose2-Home Improvement                                                                                       ***
## Loan.Purpose31-Refinance                                                                                             ***
## Loan.Purpose32-Cash Out                                                                                              ***
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                        
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                             
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                            
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                            
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                              
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                          
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                         
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                            
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                            
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                               
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                              
## Race.of.Applicant.or.Borrower..1.5-White                                                                                
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application    
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                    *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1678 on 18075 degrees of freedom
##   (4904 observations deleted due to missingness)
## Multiple R-squared:  0.05566,    Adjusted R-squared:  0.05461 
## F-statistic: 53.27 on 20 and 18075 DF,  p-value: < 2.2e-16
# Crear un modelo de regresión logística
modelo_logistico_Applicant <- glm(Action.Taken ~ Open.End.Line.of.Credit + Loan.Purpose + Bank + Reason.for.Denial..1. + Race.of.Applicant.or.Borrower..1. + Ethnicity.of.Applicant.or.Borrower..1. + Sex.of.Applicant.or.Borrower, data = loans_DF, family = "binomial")
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
# Imprimir un resumen del modelo
summary(modelo_logistico_Applicant)
## 
## Call:
## glm(formula = Action.Taken ~ Open.End.Line.of.Credit + Loan.Purpose + 
##     Bank + Reason.for.Denial..1. + Race.of.Applicant.or.Borrower..1. + 
##     Ethnicity.of.Applicant.or.Borrower..1. + Sex.of.Applicant.or.Borrower, 
##     family = "binomial", data = loans_DF)
## 
## Coefficients:
##                                                                                                                             Estimate
## (Intercept)                                                                                                                6.960e+01
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                   -5.303e-02
## Loan.Purpose2-Home Improvement                                                                                            -2.082e+01
## Loan.Purpose31-Refinance                                                                                                  -2.070e+01
## Loan.Purpose32-Cash Out                                                                                                   -2.020e+01
## BankBMO Bank N.A                                                                                                           8.757e+00
## BankFifth Third Bank N.A                                                                                                   8.952e+00
## BankJP Morgan Chase Bank                                                                                                   2.081e+00
## BankPNC Bank                                                                                                               3.524e+01
## BankUS Bank                                                                                                                2.395e+00
## BankWells Fargo                                                                                                            7.490e-01
## Reason.for.Denial..1.10-Not applicable                                                                                    -8.903e+01
## Reason.for.Denial..1.2-Employment history                                                                                 -8.919e+00
## Reason.for.Denial..1.3-Credit history                                                                                      1.698e+00
## Reason.for.Denial..1.4-Collateral                                                                                          2.249e+00
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                      2.493e+00
## Reason.for.Denial..1.6-Unverifiable information                                                                            1.135e+00
## Reason.for.Denial..1.7                                                                                                    -3.146e+00
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                          -2.844e+01
## Reason.for.Denial..1.9-Other                                                                                              -2.117e+00
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                  -1.686e+01
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                          -9.704e+00
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                               -9.695e+00
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                              -6.506e+00
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                              -6.235e+00
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                                -6.750e+00
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                            -1.152e+01
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                           -1.642e+01
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                              -1.614e+01
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                              -2.697e+01
## Race.of.Applicant.or.Borrower..1.41                                                                                       -4.878e+01
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                                  1.254e+01
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                -1.439e+01
## Race.of.Applicant.or.Borrower..1.5-White                                                                                  -1.719e+01
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application      -1.765e+01
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                         -1.957e+01
## Ethnicity.of.Applicant.or.Borrower..1.11-Mexican                                                                          -8.152e+00
## Ethnicity.of.Applicant.or.Borrower..1.12-Puerto Rican                                                                      1.069e+01
## Ethnicity.of.Applicant.or.Borrower..1.13-Cuban                                                                            -2.853e+00
## Ethnicity.of.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                         -1.524e+01
## Ethnicity.of.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                             1.594e-01
## Ethnicity.of.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application  4.354e-01
## Ethnicity.of.Applicant.or.Borrower..1.4-Not applicable                                                                     1.331e+01
## Sex.of.Applicant.or.Borrower2-Female                                                                                      -5.397e-01
## Sex.of.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application           -3.267e-01
## Sex.of.Applicant.or.Borrower4-Not applicable                                                                              -1.042e+01
##                                                                                                                           Std. Error
## (Intercept)                                                                                                                6.591e+03
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                    4.566e-01
## Loan.Purpose2-Home Improvement                                                                                             4.140e+03
## Loan.Purpose31-Refinance                                                                                                   1.882e+03
## Loan.Purpose32-Cash Out                                                                                                    2.887e+03
## BankBMO Bank N.A                                                                                                           1.769e+04
## BankFifth Third Bank N.A                                                                                                   1.406e+04
## BankJP Morgan Chase Bank                                                                                                   3.559e+03
## BankPNC Bank                                                                                                               3.503e+03
## BankUS Bank                                                                                                                4.503e+03
## BankWells Fargo                                                                                                            5.620e+03
## Reason.for.Denial..1.10-Not applicable                                                                                     5.775e+03
## Reason.for.Denial..1.2-Employment history                                                                                  2.940e+04
## Reason.for.Denial..1.3-Credit history                                                                                      6.831e+03
## Reason.for.Denial..1.4-Collateral                                                                                          7.443e+03
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                      1.934e+04
## Reason.for.Denial..1.6-Unverifiable information                                                                            1.213e+04
## Reason.for.Denial..1.7                                                                                                     1.870e+04
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                           1.520e+05
## Reason.for.Denial..1.9-Other                                                                                               1.354e+04
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                   1.256e+03
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                           1.602e+04
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                                2.352e+04
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                               1.937e+04
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                               8.955e+04
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                                 3.867e+04
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                             4.136e+04
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                            2.525e+04
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                               1.256e+03
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                               7.604e+04
## Race.of.Applicant.or.Borrower..1.41                                                                                        2.161e+05
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                                  2.160e+05
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                 8.921e+03
## Race.of.Applicant.or.Borrower..1.5-White                                                                                   1.256e+03
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application       1.256e+03
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                          7.706e+04
## Ethnicity.of.Applicant.or.Borrower..1.11-Mexican                                                                           1.364e+04
## Ethnicity.of.Applicant.or.Borrower..1.12-Puerto Rican                                                                      2.691e+04
## Ethnicity.of.Applicant.or.Borrower..1.13-Cuban                                                                             1.667e+05
## Ethnicity.of.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                          2.521e+03
## Ethnicity.of.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                             4.031e-01
## Ethnicity.of.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application  7.728e-01
## Ethnicity.of.Applicant.or.Borrower..1.4-Not applicable                                                                     9.569e+04
## Sex.of.Applicant.or.Borrower2-Female                                                                                       3.115e-01
## Sex.of.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application            4.527e-01
## Sex.of.Applicant.or.Borrower4-Not applicable                                                                               5.675e+04
##                                                                                                                           z value
## (Intercept)                                                                                                                 0.011
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                    -0.116
## Loan.Purpose2-Home Improvement                                                                                             -0.005
## Loan.Purpose31-Refinance                                                                                                   -0.011
## Loan.Purpose32-Cash Out                                                                                                    -0.007
## BankBMO Bank N.A                                                                                                            0.000
## BankFifth Third Bank N.A                                                                                                    0.001
## BankJP Morgan Chase Bank                                                                                                    0.001
## BankPNC Bank                                                                                                                0.010
## BankUS Bank                                                                                                                 0.001
## BankWells Fargo                                                                                                             0.000
## Reason.for.Denial..1.10-Not applicable                                                                                     -0.015
## Reason.for.Denial..1.2-Employment history                                                                                   0.000
## Reason.for.Denial..1.3-Credit history                                                                                       0.000
## Reason.for.Denial..1.4-Collateral                                                                                           0.000
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                       0.000
## Reason.for.Denial..1.6-Unverifiable information                                                                             0.000
## Reason.for.Denial..1.7                                                                                                      0.000
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                            0.000
## Reason.for.Denial..1.9-Other                                                                                                0.000
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                   -0.013
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                           -0.001
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                                 0.000
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                                0.000
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                                0.000
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                                  0.000
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                              0.000
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                            -0.001
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                               -0.013
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                                0.000
## Race.of.Applicant.or.Borrower..1.41                                                                                         0.000
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                                   0.000
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                 -0.002
## Race.of.Applicant.or.Borrower..1.5-White                                                                                   -0.014
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application       -0.014
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                           0.000
## Ethnicity.of.Applicant.or.Borrower..1.11-Mexican                                                                           -0.001
## Ethnicity.of.Applicant.or.Borrower..1.12-Puerto Rican                                                                       0.000
## Ethnicity.of.Applicant.or.Borrower..1.13-Cuban                                                                              0.000
## Ethnicity.of.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                          -0.006
## Ethnicity.of.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                              0.396
## Ethnicity.of.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application   0.563
## Ethnicity.of.Applicant.or.Borrower..1.4-Not applicable                                                                      0.000
## Sex.of.Applicant.or.Borrower2-Female                                                                                       -1.733
## Sex.of.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application            -0.722
## Sex.of.Applicant.or.Borrower4-Not applicable                                                                                0.000
##                                                                                                                           Pr(>|z|)
## (Intercept)                                                                                                                 0.9916
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                     0.9075
## Loan.Purpose2-Home Improvement                                                                                              0.9960
## Loan.Purpose31-Refinance                                                                                                    0.9912
## Loan.Purpose32-Cash Out                                                                                                     0.9944
## BankBMO Bank N.A                                                                                                            0.9996
## BankFifth Third Bank N.A                                                                                                    0.9995
## BankJP Morgan Chase Bank                                                                                                    0.9995
## BankPNC Bank                                                                                                                0.9920
## BankUS Bank                                                                                                                 0.9996
## BankWells Fargo                                                                                                             0.9999
## Reason.for.Denial..1.10-Not applicable                                                                                      0.9877
## Reason.for.Denial..1.2-Employment history                                                                                   0.9998
## Reason.for.Denial..1.3-Credit history                                                                                       0.9998
## Reason.for.Denial..1.4-Collateral                                                                                           0.9998
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                       0.9999
## Reason.for.Denial..1.6-Unverifiable information                                                                             0.9999
## Reason.for.Denial..1.7                                                                                                      0.9999
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                            0.9999
## Reason.for.Denial..1.9-Other                                                                                                0.9999
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                    0.9893
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                            0.9995
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                                 0.9997
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                                0.9997
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                                0.9999
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                                  0.9999
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                              0.9998
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                             0.9995
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                                0.9898
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                                0.9997
## Race.of.Applicant.or.Borrower..1.41                                                                                         0.9998
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                                   1.0000
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                  0.9987
## Race.of.Applicant.or.Borrower..1.5-White                                                                                    0.9891
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application        0.9888
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                           0.9998
## Ethnicity.of.Applicant.or.Borrower..1.11-Mexican                                                                            0.9995
## Ethnicity.of.Applicant.or.Borrower..1.12-Puerto Rican                                                                       0.9997
## Ethnicity.of.Applicant.or.Borrower..1.13-Cuban                                                                              1.0000
## Ethnicity.of.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                           0.9952
## Ethnicity.of.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                              0.6924
## Ethnicity.of.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application   0.5731
## Ethnicity.of.Applicant.or.Borrower..1.4-Not applicable                                                                      0.9999
## Sex.of.Applicant.or.Borrower2-Female                                                                                        0.0832
## Sex.of.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application             0.4706
## Sex.of.Applicant.or.Borrower4-Not applicable                                                                                0.9999
##                                                                                                                            
## (Intercept)                                                                                                                
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                    
## Loan.Purpose2-Home Improvement                                                                                             
## Loan.Purpose31-Refinance                                                                                                   
## Loan.Purpose32-Cash Out                                                                                                    
## BankBMO Bank N.A                                                                                                           
## BankFifth Third Bank N.A                                                                                                   
## BankJP Morgan Chase Bank                                                                                                   
## BankPNC Bank                                                                                                               
## BankUS Bank                                                                                                                
## BankWells Fargo                                                                                                            
## Reason.for.Denial..1.10-Not applicable                                                                                     
## Reason.for.Denial..1.2-Employment history                                                                                  
## Reason.for.Denial..1.3-Credit history                                                                                      
## Reason.for.Denial..1.4-Collateral                                                                                          
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                      
## Reason.for.Denial..1.6-Unverifiable information                                                                            
## Reason.for.Denial..1.7                                                                                                     
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                           
## Reason.for.Denial..1.9-Other                                                                                               
## Race.of.Applicant.or.Borrower..1.2-Asian                                                                                   
## Race.of.Applicant.or.Borrower..1.21-Asian Indian                                                                           
## Race.of.Applicant.or.Borrower..1.22-Chinese                                                                                
## Race.of.Applicant.or.Borrower..1.23-Filipino                                                                               
## Race.of.Applicant.or.Borrower..1.24-Japanese                                                                               
## Race.of.Applicant.or.Borrower..1.25-Korean                                                                                 
## Race.of.Applicant.or.Borrower..1.26-Vietnamese                                                                             
## Race.of.Applicant.or.Borrower..1.27-Other Asian                                                                            
## Race.of.Applicant.or.Borrower..1.3-Black or African American                                                               
## Race.of.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                               
## Race.of.Applicant.or.Borrower..1.41                                                                                        
## Race.of.Applicant.or.Borrower..1.42-Guamanian or Chamorro                                                                  
## Race.of.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                 
## Race.of.Applicant.or.Borrower..1.5-White                                                                                   
## Race.of.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application       
## Race.of.Applicant.or.Borrower..1.7-Not applicable                                                                          
## Ethnicity.of.Applicant.or.Borrower..1.11-Mexican                                                                           
## Ethnicity.of.Applicant.or.Borrower..1.12-Puerto Rican                                                                      
## Ethnicity.of.Applicant.or.Borrower..1.13-Cuban                                                                             
## Ethnicity.of.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                          
## Ethnicity.of.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                             
## Ethnicity.of.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application  
## Ethnicity.of.Applicant.or.Borrower..1.4-Not applicable                                                                     
## Sex.of.Applicant.or.Borrower2-Female                                                                                      .
## Sex.of.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application            
## Sex.of.Applicant.or.Borrower4-Not applicable                                                                               
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 23839.28  on 22999  degrees of freedom
## Residual deviance:   410.58  on 22954  degrees of freedom
## AIC: 502.58
## 
## Number of Fisher Scoring iterations: 24
# Crear un modelo de regresión logística
modelo_logistico_Copplicant <- glm(Action.Taken ~ Open.End.Line.of.Credit + Loan.Purpose + Bank + Reason.for.Denial..1. + Race.of.Co.Applicant.or.Borrower..1. + Ethnicity.of.Co.Applicant.or.Borrower..1. + Sex.of.Co.Applicant.or.Borrower, data = loans_DF, family = "binomial")
## Warning: glm.fit: algorithm did not converge

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
# Imprimir un resumen del modelo
summary(modelo_logistico_Copplicant)
## 
## Call:
## glm(formula = Action.Taken ~ Open.End.Line.of.Credit + Loan.Purpose + 
##     Bank + Reason.for.Denial..1. + Race.of.Co.Applicant.or.Borrower..1. + 
##     Ethnicity.of.Co.Applicant.or.Borrower..1. + Sex.of.Co.Applicant.or.Borrower, 
##     family = "binomial", data = loans_DF)
## 
## Coefficients: (1 not defined because of singularities)
##                                                                                                                                Estimate
## (Intercept)                                                                                                                   6.989e+01
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                      -2.581e-01
## Loan.Purpose2-Home Improvement                                                                                               -2.241e+01
## Loan.Purpose31-Refinance                                                                                                     -2.162e+01
## Loan.Purpose32-Cash Out                                                                                                      -2.135e+01
## BankBMO Bank N.A                                                                                                              1.229e+01
## BankFifth Third Bank N.A                                                                                                      1.318e+01
## BankJP Morgan Chase Bank                                                                                                      3.226e-01
## BankPNC Bank                                                                                                                  3.702e+01
## BankUS Bank                                                                                                                   7.464e-01
## BankWells Fargo                                                                                                               8.551e-01
## Reason.for.Denial..1.10-Not applicable                                                                                       -9.708e+01
## Reason.for.Denial..1.2-Employment history                                                                                    -1.183e+01
## Reason.for.Denial..1.3-Credit history                                                                                         2.044e-01
## Reason.for.Denial..1.4-Collateral                                                                                            -2.860e-01
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                        -1.196e+01
## Reason.for.Denial..1.6-Unverifiable information                                                                              -1.125e+01
## Reason.for.Denial..1.7                                                                                                       -1.235e+01
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                             -3.330e+01
## Reason.for.Denial..1.9-Other                                                                                                 -1.193e+01
## Race.of.Co.Applicant.or.Borrower..1.2-Asian                                                                                   1.493e-01
## Race.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                           1.806e+01
## Race.of.Co.Applicant.or.Borrower..1.22-Chinese                                                                               -1.729e+01
## Race.of.Co.Applicant.or.Borrower..1.23-Filipino                                                                               2.506e+00
## Race.of.Co.Applicant.or.Borrower..1.24-Japanese                                                                               2.548e+00
## Race.of.Co.Applicant.or.Borrower..1.25-Korean                                                                                 3.802e+00
## Race.of.Co.Applicant.or.Borrower..1.26-Vietnamese                                                                             2.111e+00
## Race.of.Co.Applicant.or.Borrower..1.27-Other Asian                                                                            4.705e-01
## Race.of.Co.Applicant.or.Borrower..1.3-Black or African American                                                               2.632e+00
## Race.of.Co.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                              -7.078e+00
## Race.of.Co.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                -1.027e+00
## Race.of.Co.Applicant.or.Borrower..1.5-White                                                                                   1.172e-01
## Race.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application      -1.349e+00
## Race.of.Co.Applicant.or.Borrower..1.7-Not applicable                                                                         -2.741e-01
## Race.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                         1.679e+12
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-American Indian or Alaska Native                                                  -3.141e-02
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-Hispanic or Latino                                                                -1.108e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.11-Mexican                                                                          -9.995e+00
## Ethnicity.of.Co.Applicant.or.Borrower..1.12-Puerto Rican                                                                     -2.761e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.13-Cuban                                                                             1.172e+00
## Ethnicity.of.Co.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                         -1.378e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                            -1.123e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                     -1.746e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application -1.015e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.4-Not applicable                                                                    -1.267e+01
## Ethnicity.of.Co.Applicant.or.Borrower..1.5-White                                                                             -1.679e+12
## Ethnicity.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  1.760e+00
## Ethnicity.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                   -1.679e+12
## Sex.of.Co.Applicant.or.Borrower2-Female                                                                                      -2.773e-01
## Sex.of.Co.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application            3.952e-01
## Sex.of.Co.Applicant.or.Borrower4-Not applicable                                                                               1.583e+00
## Sex.of.Co.Applicant.or.Borrower5-No co-applicant                                                                                     NA
## Sex.of.Co.Applicant.or.Borrower6-Applicant/Co-Applicant selected both male and female                                         1.222e+01
##                                                                                                                              Std. Error
## (Intercept)                                                                                                                   8.453e+04
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                       4.569e-01
## Loan.Purpose2-Home Improvement                                                                                                8.622e+03
## Loan.Purpose31-Refinance                                                                                                      3.038e+03
## Loan.Purpose32-Cash Out                                                                                                       5.106e+03
## BankBMO Bank N.A                                                                                                              1.884e+04
## BankFifth Third Bank N.A                                                                                                      1.334e+04
## BankJP Morgan Chase Bank                                                                                                      6.926e+03
## BankPNC Bank                                                                                                                  6.808e+03
## BankUS Bank                                                                                                                   8.218e+03
## BankWells Fargo                                                                                                               1.000e+04
## Reason.for.Denial..1.10-Not applicable                                                                                        1.054e+04
## Reason.for.Denial..1.2-Employment history                                                                                     4.699e+04
## Reason.for.Denial..1.3-Credit history                                                                                         1.457e+04
## Reason.for.Denial..1.4-Collateral                                                                                             1.243e+04
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                         3.547e+04
## Reason.for.Denial..1.6-Unverifiable information                                                                               2.460e+04
## Reason.for.Denial..1.7                                                                                                        2.445e+04
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                              2.188e+05
## Reason.for.Denial..1.9-Other                                                                                                  2.085e+04
## Race.of.Co.Applicant.or.Borrower..1.2-Asian                                                                                   8.258e+04
## Race.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                           8.261e+04
## Race.of.Co.Applicant.or.Borrower..1.22-Chinese                                                                                8.286e+04
## Race.of.Co.Applicant.or.Borrower..1.23-Filipino                                                                               9.228e+04
## Race.of.Co.Applicant.or.Borrower..1.24-Japanese                                                                               1.453e+05
## Race.of.Co.Applicant.or.Borrower..1.25-Korean                                                                                 1.033e+05
## Race.of.Co.Applicant.or.Borrower..1.26-Vietnamese                                                                             1.357e+05
## Race.of.Co.Applicant.or.Borrower..1.27-Other Asian                                                                            1.155e+05
## Race.of.Co.Applicant.or.Borrower..1.3-Black or African American                                                               8.258e+04
## Race.of.Co.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                               4.745e+07
## Race.of.Co.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                 1.501e+05
## Race.of.Co.Applicant.or.Borrower..1.5-White                                                                                   8.258e+04
## Race.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application       8.258e+04
## Race.of.Co.Applicant.or.Borrower..1.7-Not applicable                                                                          2.317e+05
## Race.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                         4.537e+13
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-American Indian or Alaska Native                                                   2.389e+05
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-Hispanic or Latino                                                                 1.305e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.11-Mexican                                                                           3.158e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.12-Puerto Rican                                                                      1.399e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.13-Cuban                                                                             1.099e+05
## Ethnicity.of.Co.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                          5.877e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                             1.305e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                      6.796e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application  1.305e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.4-Not applicable                                                                     3.225e+05
## Ethnicity.of.Co.Applicant.or.Borrower..1.5-White                                                                              4.537e+13
## Ethnicity.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application  3.851e+04
## Ethnicity.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                    4.537e+13
## Sex.of.Co.Applicant.or.Borrower2-Female                                                                                       5.635e-01
## Sex.of.Co.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application            8.805e-01
## Sex.of.Co.Applicant.or.Borrower4-Not applicable                                                                               3.943e+05
## Sex.of.Co.Applicant.or.Borrower5-No co-applicant                                                                                     NA
## Sex.of.Co.Applicant.or.Borrower6-Applicant/Co-Applicant selected both male and female                                         1.621e+05
##                                                                                                                              z value
## (Intercept)                                                                                                                    0.001
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                       -0.565
## Loan.Purpose2-Home Improvement                                                                                                -0.003
## Loan.Purpose31-Refinance                                                                                                      -0.007
## Loan.Purpose32-Cash Out                                                                                                       -0.004
## BankBMO Bank N.A                                                                                                               0.001
## BankFifth Third Bank N.A                                                                                                       0.001
## BankJP Morgan Chase Bank                                                                                                       0.000
## BankPNC Bank                                                                                                                   0.005
## BankUS Bank                                                                                                                    0.000
## BankWells Fargo                                                                                                                0.000
## Reason.for.Denial..1.10-Not applicable                                                                                        -0.009
## Reason.for.Denial..1.2-Employment history                                                                                      0.000
## Reason.for.Denial..1.3-Credit history                                                                                          0.000
## Reason.for.Denial..1.4-Collateral                                                                                              0.000
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                          0.000
## Reason.for.Denial..1.6-Unverifiable information                                                                                0.000
## Reason.for.Denial..1.7                                                                                                        -0.001
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                               0.000
## Reason.for.Denial..1.9-Other                                                                                                  -0.001
## Race.of.Co.Applicant.or.Borrower..1.2-Asian                                                                                    0.000
## Race.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                            0.000
## Race.of.Co.Applicant.or.Borrower..1.22-Chinese                                                                                 0.000
## Race.of.Co.Applicant.or.Borrower..1.23-Filipino                                                                                0.000
## Race.of.Co.Applicant.or.Borrower..1.24-Japanese                                                                                0.000
## Race.of.Co.Applicant.or.Borrower..1.25-Korean                                                                                  0.000
## Race.of.Co.Applicant.or.Borrower..1.26-Vietnamese                                                                              0.000
## Race.of.Co.Applicant.or.Borrower..1.27-Other Asian                                                                             0.000
## Race.of.Co.Applicant.or.Borrower..1.3-Black or African American                                                                0.000
## Race.of.Co.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                                0.000
## Race.of.Co.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                  0.000
## Race.of.Co.Applicant.or.Borrower..1.5-White                                                                                    0.000
## Race.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application        0.000
## Race.of.Co.Applicant.or.Borrower..1.7-Not applicable                                                                           0.000
## Race.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                          0.037
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-American Indian or Alaska Native                                                    0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-Hispanic or Latino                                                                 -0.001
## Ethnicity.of.Co.Applicant.or.Borrower..1.11-Mexican                                                                            0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.12-Puerto Rican                                                                      -0.002
## Ethnicity.of.Co.Applicant.or.Borrower..1.13-Cuban                                                                              0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                           0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                             -0.001
## Ethnicity.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                       0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application  -0.001
## Ethnicity.of.Co.Applicant.or.Borrower..1.4-Not applicable                                                                      0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.5-White                                                                              -0.037
## Ethnicity.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application   0.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                    -0.037
## Sex.of.Co.Applicant.or.Borrower2-Female                                                                                       -0.492
## Sex.of.Co.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application             0.449
## Sex.of.Co.Applicant.or.Borrower4-Not applicable                                                                                0.000
## Sex.of.Co.Applicant.or.Borrower5-No co-applicant                                                                                  NA
## Sex.of.Co.Applicant.or.Borrower6-Applicant/Co-Applicant selected both male and female                                          0.000
##                                                                                                                              Pr(>|z|)
## (Intercept)                                                                                                                     0.999
## Open.End.Line.of.Credit2-Not an open-end line of credit                                                                         0.572
## Loan.Purpose2-Home Improvement                                                                                                  0.998
## Loan.Purpose31-Refinance                                                                                                        0.994
## Loan.Purpose32-Cash Out                                                                                                         0.997
## BankBMO Bank N.A                                                                                                                0.999
## BankFifth Third Bank N.A                                                                                                        0.999
## BankJP Morgan Chase Bank                                                                                                        1.000
## BankPNC Bank                                                                                                                    0.996
## BankUS Bank                                                                                                                     1.000
## BankWells Fargo                                                                                                                 1.000
## Reason.for.Denial..1.10-Not applicable                                                                                          0.993
## Reason.for.Denial..1.2-Employment history                                                                                       1.000
## Reason.for.Denial..1.3-Credit history                                                                                           1.000
## Reason.for.Denial..1.4-Collateral                                                                                               1.000
## Reason.for.Denial..1.5-Insufficient cash (downpayment, closing costs)                                                           1.000
## Reason.for.Denial..1.6-Unverifiable information                                                                                 1.000
## Reason.for.Denial..1.7                                                                                                          1.000
## Reason.for.Denial..1.8-Mortgage insurance denied                                                                                1.000
## Reason.for.Denial..1.9-Other                                                                                                    1.000
## Race.of.Co.Applicant.or.Borrower..1.2-Asian                                                                                     1.000
## Race.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                             1.000
## Race.of.Co.Applicant.or.Borrower..1.22-Chinese                                                                                  1.000
## Race.of.Co.Applicant.or.Borrower..1.23-Filipino                                                                                 1.000
## Race.of.Co.Applicant.or.Borrower..1.24-Japanese                                                                                 1.000
## Race.of.Co.Applicant.or.Borrower..1.25-Korean                                                                                   1.000
## Race.of.Co.Applicant.or.Borrower..1.26-Vietnamese                                                                               1.000
## Race.of.Co.Applicant.or.Borrower..1.27-Other Asian                                                                              1.000
## Race.of.Co.Applicant.or.Borrower..1.3-Black or African American                                                                 1.000
## Race.of.Co.Applicant.or.Borrower..1.4-Native Hawaiian or Other Pacific Islander                                                 1.000
## Race.of.Co.Applicant.or.Borrower..1.44-Other Pacific Islander                                                                   1.000
## Race.of.Co.Applicant.or.Borrower..1.5-White                                                                                     1.000
## Race.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application         1.000
## Race.of.Co.Applicant.or.Borrower..1.7-Not applicable                                                                            1.000
## Race.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                           0.970
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-American Indian or Alaska Native                                                     1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.1-Hispanic or Latino                                                                   0.999
## Ethnicity.of.Co.Applicant.or.Borrower..1.11-Mexican                                                                             1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.12-Puerto Rican                                                                        0.998
## Ethnicity.of.Co.Applicant.or.Borrower..1.13-Cuban                                                                               1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.14-Other Hispanic or Latino                                                            1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.2-Not Hispanic or Latino                                                               0.999
## Ethnicity.of.Co.Applicant.or.Borrower..1.21-Asian Indian                                                                        1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.3-Information not provided by applicant in mail, internet, or telephone application    0.999
## Ethnicity.of.Co.Applicant.or.Borrower..1.4-Not applicable                                                                       1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.5-White                                                                                0.970
## Ethnicity.of.Co.Applicant.or.Borrower..1.6-Information not provided by applicant in mail, internet, or telephone application    1.000
## Ethnicity.of.Co.Applicant.or.Borrower..1.8-No co-applicant                                                                      0.970
## Sex.of.Co.Applicant.or.Borrower2-Female                                                                                         0.623
## Sex.of.Co.Applicant.or.Borrower3-Information not provided by applicant in mail, internet, or telephone application              0.654
## Sex.of.Co.Applicant.or.Borrower4-Not applicable                                                                                 1.000
## Sex.of.Co.Applicant.or.Borrower5-No co-applicant                                                                                   NA
## Sex.of.Co.Applicant.or.Borrower6-Applicant/Co-Applicant selected both male and female                                           1.000
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 23839.28  on 22999  degrees of freedom
## Residual deviance:   414.68  on 22948  degrees of freedom
## AIC: 518.68
## 
## Number of Fisher Scoring iterations: 25

5. Answer the questions below:

Question 5: “How does the loan amount vary across the 5 main loan purposes, and is there a significant difference in mean loan amounts between these purposes?” Identify how loan amounts differ across these purposes to provide insights into the financial needs associated with different loan intents.

# Crea un gráfico interactivo de caja con plotly
interactive_plot <- ggplot(loans_DF, aes(x = Loan.Purpose, y = Loan.Amount, fill = Loan.Purpose)) +
  geom_boxplot() +
  labs(title = "Distribution of Loan Amounts Across Loan Purposes",
       x = "Loan Purpose",
       y = "Loan Amount",
       fill = "Loan Purpose") +
  scale_y_continuous(labels = scales::dollar_format(scale = 0.001, suffix = "k")) +  # Formato en dólares con escala
  theme_minimal()

# Convierte el gráfico a un gráfico interactivo con plotly
interactive_plot <- ggplotly(interactive_plot)

# Muestra el gráfico interactivo
interactive_plot

Please review the same homework in google colab (Python) following this link: Google Colab notebook

And the same file has been uploaded in my Github repository of the class please follow this link: My GitHub Repository